package persistence;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import persistence.exception.DAOException;

public class SubscriptionDAOTestImpl extends SubscriptionDAOJdbcImpl implements SubscriptionDAO {
	private List<Subscription> subscriptions;
	private SupplierDAO supplierDAO;
	private CostUnitDAO costUnitDAO;
	private PurchaserDAO purchaserDAO;
	private PeriodicalDAOJdbcImpl periodicalDAO;
	private BindingDetailsDAO bindingDetailsDAO;	
	
	public SubscriptionDAOTestImpl() {
		subscriptions = new ArrayList<Subscription>();
	}

	@Override
	public List<Subscription> getAllSubscriptionsAsc() {
		Calendar cal = Calendar.getInstance();
		cal.set(2002, 6, 4);
		Date startDate = cal.getTime();
		cal.set(2005, 1, 1);
		Date endDate = cal.getTime();
		cal.set(2004, 12, 12);
		Date currentIssueDate = cal.getTime();
		cal.set(2004, 31, 12);
		Date paidUntil = cal.getTime();
		cal.set(2002, 3, 3);
		Date orderDate = cal.getTime();
		
		//setting invalid Date
		cal.set(Calendar.YEAR, 2011);
		cal.set(Calendar.MONTH, Calendar.FEBRUARY);
		cal.set(Calendar.DAY_OF_MONTH, 29);
		Date testDate = cal.getTime();
		System.out.println(testDate);
		
		
		LibraryLocation libraryLocation = new LibraryLocation(1, new City(2, 8605, "Kapfenberg"));
		Supplier supplier = new Supplier(1, "Leykam", 2485895995l, "Mayerhofer-Straße", new City(5, 8600, "Bruck an der Mur"));
		CostUnit costUnit = new CostUnit(1, "ITM", 340, libraryLocation);
		Purchaser purchaser = new Purchaser(4, "Sonja", "Gögele", libraryLocation);
		PredefinedParam publicationInterval = new PredefinedParam(1, "Erscheinungsintervall");
		PredefinedEntry publicationInterval1 = new PredefinedEntry(publicationInterval, 1, "monatlich");
		PredefinedParam kindOfPublication = new PredefinedParam(2, "Erscheinungsweise");
		PredefinedEntry kindOfPublication1 = new PredefinedEntry (kindOfPublication, 2, "Print + E-Journal");
		PredefinedParam kindOfOnlineAccess = new PredefinedParam(3, "Online-Zugang");
		PredefinedEntry kindOfOnlineAccess1 = new PredefinedEntry(kindOfOnlineAccess, 3, "kostenpflichtiger Zugang abonniert");
		
		
		Periodical periodical1= new Periodical(1, "Abwasser", "Abwasserwirtschafts-Verlag", "1234-5678", publicationInterval1, "123123-12332", kindOfPublication1, kindOfOnlineAccess1, "user: fhj87889, pass: ac993fhjas", "12345-678910", "www.abw-journal.de", Boolean.TRUE, Boolean.FALSE, null);
		Periodical periodical2 = new Periodical(7, "Bautechnisches Journal", "Architekturverlag", "2345-6789", publicationInterval1, "12222-241656", kindOfPublication1, kindOfOnlineAccess1, "user: qwew89, pass: acH)=9jas", "88384-677703", "www.archv.at/btj", Boolean.FALSE, Boolean.FALSE, null);
		BindingDetails bindingDetails = new BindingDetails(1, "gründer Einband", "Abwasser + Jahrgang", null);
		PredefinedParam status = new PredefinedParam(1, "Abo-Status");
		PredefinedParam kindOfAcquisition = new PredefinedParam(2, "Erwerbungsart");
		PredefinedParam currency = new PredefinedParam(3, "Währung");
		PredefinedParam kindOfStorage = new PredefinedParam(4,"Aufbewahren");
		
		PredefinedEntry status1 = new PredefinedEntry(status, 1, "storniert");
		PredefinedEntry status2 = new PredefinedEntry(status, 2, "laufend");
		PredefinedEntry kindOfAcqu1 = new PredefinedEntry (kindOfAcquisition, 3, "Kauf");
		PredefinedEntry currency1 = new PredefinedEntry (currency, 4, "Euro (€)");
		PredefinedEntry kindOfStorage1 = new PredefinedEntry (kindOfStorage, 5, "In Schuber (1 Jahr)");
		
		Subscription subscription1 = new Subscription (1, "1234_ac", status1, 33.2f, 30.0f, startDate, endDate, "Auflage", paidUntil, "3 months", Boolean.TRUE, "SQ-44533-3", orderDate, "BC-3884-34q3", currentIssueDate, kindOfAcqu1,"note", "online note", currency1, kindOfStorage1, libraryLocation, supplier, costUnit, purchaser, periodical1, bindingDetails, 40);
		Subscription subscription2 = new Subscription (7, "1298/af7", status2, 34.0f, 26.7f, startDate, null, "Auflage", paidUntil, "7 weeks", Boolean.TRUE, "ST-22452", orderDate, "BC-3999520-2", currentIssueDate, kindOfAcqu1, "note 2", "online note 2", currency1, kindOfStorage1, libraryLocation, supplier, costUnit, purchaser, periodical2, bindingDetails, 40);
		subscriptions.add(subscription1);
		subscriptions.add(subscription2);
		return subscriptions;
	}

	@Override
	public Subscription createSubscription() {
		return null;
		
//		String sql = "INSERT INTO abos (id, lieferanten_id, abo_status, preis, preis_vorjahr," +
//		 " interner_standort, bibliotheksstandorte_id, erwerbungsart, bestellt_am, abo_startdatum," +
//		 " eingangsdatum_aktuelles_heft, abo_enddatum, bezahlt_bis, kuendigungsfrist, online_in_aleph," +
//	     " kostenstellen_id, besteller_id, sap_kreditor, signatur, barcode," +
//	     " anmerkungen, anmerkungen_online, waehrung, aufbewahrungsart, zeitschriften_id ) VALUES" +
//		 	" (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
////TODO: Datensatz für BindingDetails ?
//		return null;
	}
	
	public Subscription saveSubscription(Subscription sub) throws DAOException{
		subscriptions.add(sub);
		return sub;
	}

}
